import java.util.Scanner;

/**
 * 查找两个字符串a,b中的最长公共子串
 */
public class PublicSubString {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String string1 = scanner.nextLine();
            String string2 = scanner.nextLine();
            String max = string1.length() >= string2.length() ? string1 :string2;
            String min = string1.length() >= string2.length() ? string2 :string1;
            int length = 0;
            String result = "";
            for (int i=0; i<min.length(); i++) {
                for (int j=i+1; j<=min.length(); j++) {
                    if (max.contains(min.substring(i, j)) && j-i>length) {
                        length = j-i;
                        result = min.substring(i, j);
                    }
                }
            }
            System.out.println(result);
        }
    }
}
